<script>
import {visitPath} from "@/Interface/FileApi";
import moment from "moment";
import {dictStatus, isEmpty} from "../../Config/Tool";
import {queryDictItem} from "@/Interface/DictApi";
import {deleteCollect, queryCollect} from "@/Interface/CollectApi";

export default {
  computed: {
    moment() {
      return moment
    }
  },
  data(){
    return {
      list:[],
      dict2:[],
      dict3:[],
      dict4:[],
      dict5:[],
      dict6:[],
      show:true,
      commentShow:false,
      updateId:0,
      commentInfo:{
        score:null,
        comment:"",
        roomId:'',
        hotelId:'',
        userId:0
      },
    }
  },
  mounted(){
    this.queryDictItemFun([2]);
    this.queryCollectFun();
  },
  methods:{
    deleteCollect,
    dictStatus,
    visitPath() {
      return visitPath
    },
    /**
     * 查询我的收藏
     */
    queryCollectFun(){
      queryCollect({userId:localStorage.getItem("userId")}).then(res=>{
        console.log(res)
        if(res.code===200) this.list=res.data;
        this.show=false;
      })
    },
    /**
     * 查询字典值
     */
    queryDictItemFun(e){
      e.forEach(item=>{
        queryDictItem({id:item}).then(res=>{
          switch (item){
            case 2:
              this.dict2 = res.data;
              break;
            case 3:
              this.dict3 = res.data;
              break;
            case 4:
              this.dict4 = res.data;
              break;
            case 5:
              this.dict5 = res.data;
              break;
            default:
              this.dict4 = res.data;
              break;
          }
        })
      })
    },
    /**
     * 取消收藏
     */
    deleteCollectFun(item){
      deleteCollect({id:item.id}).then(res=>{
        if(res.code===200){
          this.queryCollectFun();
          this.$message.success("取消收藏成功");
        }else {
          this.$message.error(res.msg)
        }
      })
    },
    /**
     * 跳转预定
     */
    navToDetail(item) {
      this.$router.push({ path: '/front/hotel', query: { id: item.hotelId } });
    },
  }

}
</script>

<template>
  <div class="body">
    <el-skeleton :rows="16" v-show="show" animated />
    <div v-if="list.length>=1" class="content">
      <div v-for="item in list" class="item" @click="navToDetail(item)">
        <!--商家信息-->
        <div class="item-hand">
          <!--商家头像-->
          <div style="height: 40px;display: flex;align-items: center">
            <img style="width: 35px;height: 35px;border-radius: 50%" :src="visitPath()+item?.hotelInfo?.avatar" />
            <span style="margin-left: 10px;font-size: 1.2rem;color: #0F294DFF;font-weight: bold">{{item?.hotelInfo?.name}}</span>
          </div>
          <!--订单状态-->
          <div style="display: flex;align-items: center">
            <span style="margin-right: 10px;color: #003B95">已收藏</span>
            <span style="width: 30px;height: 30px;
            border-radius: 5px;
            display: flex;align-items: center;
            justify-content: center;background-color: #003B95;
            color: white">{{item.roomInfo.score}}</span>
          </div>
        </div>
        <!--房间信息-->
        <div class="item-content">
          <!--房间图片-->
          <div class="item-content-img">
            <img :src=" visitPath()+ item.roomInfo?.imageList[0]?.img" style="width: 100%;height: 100%;border-radius: 3px">
          </div>
          <div class="item-content-info">
            <div style="font-size: 1.5rem;color: #003B95">
            <span>{{item.roomInfo.roomName}}</span>
            </div>
            <div style="color:#003B95">
             <span>￥ {{item.roomInfo.price}}</span>
            </div>
            <div style="width: 90%;color: #a6a6a6">
                 <span>{{item.roomInfo.description}}</span>
            </div>
          </div>
        </div>
        <!--按钮组-->
        <div class="item-btn">
          <el-button type="warning"  @click="deleteCollectFun(item)">取消收藏</el-button>
        </div>
      </div>
    </div>
    <el-empty v-else style="margin-top: 10%"  description="暂无收藏"></el-empty>
  </div>
</template>

<style scoped>
.item-content-info{
  width: 100%;
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
}
.item-content-img{
  width: 100px;
  height: 100px;
}
.item-btn{
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.item-content{
  margin-top: 10px;
  display: flex;
  justify-content: center;
}
.item-hand{
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.item{
  width: 100%;
  height: auto;
  background-color: #f8f8f8;
  min-height: 100px;
  margin-bottom: 10px;
  padding: 15px;
  border-radius: 8px;
}
.content{
  width: 100%;
  height: auto;
  padding: 10px;
  -ms-overflow-style: none;
}
.body{
  width: 100vw;
  height: auto;
  overflow-y: scroll;
  -ms-overflow-style: none;
  -ms-overflow-style: none;
}
::-webkit-scrollbar {
  display: none;
}


</style>
